#!/bin/sh

set -xe

DIR=$(cd $(dirname "$0"); pwd)
cd "$DIR"

. ./init.sh
export USER_ID=$(id -ur)
export GROUP_ID=$(id -gr)

DOCKER_PROJECT_NAME="${DOCKER_PROJECT_NAME:-fireworqbuild}"
DOCKER_COMPOSE="$DOCKER_COMPOSE -p $DOCKER_PROJECT_NAME -f docker-compose.build.yml"

$DOCKER_COMPOSE build --force-rm
trap "" INT TERM
$DOCKER_COMPOSE up --abort-on-container-exit
status=$?

$DOCKER_COMPOSE down -v
docker rmi "${DOCKER_PROJECT_NAME}_code"
docker rmi "${DOCKER_PROJECT_NAME}_fireworq"

exit $status
